package com.upcode.weighing.vo.req.pc;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

@Data
@EqualsAndHashCode(callSuper=false)
public class EtcPartnerDetailReqVo {

    /**
     * 合伙人姓名
     */
    private String partnerName;

    /**
     * 合伙人营销编码
     */
    private String marketerCode;

    /**
     * 合伙人注册来源
     */
    private Integer registerSource;

    /**
     * 订单开始时间
     */
    private String startTime;

    /**
     * 订单结束时间
     */
    private String endTime;

    /**
     * 车牌号
     */
    private String vehicleId;

    public String checkParams(int type){
        if(type == 2 && StringUtils.isBlank(marketerCode)){
            return "合伙人营销编码不可为空";
        }
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        if(StringUtils.isNotBlank(startTime) && StringUtils.isBlank(endTime)){
            LocalDate nowDate = LocalDate.now();
            endTime = nowDate.format(dtf);
        }
        if(StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime)){
            LocalDate startDate = LocalDate.parse(startTime, dtf);
            LocalDate endDate = LocalDate.parse(endTime, dtf);
            if(endDate.isBefore(startDate)){
                return "订单结束日期不能大于订单开始日期";
            }
            startTime += " 00:00:00";
            endTime += " 23:59:59";
        }
        return null;
    }
}
